/*

Make Appendix Table A.8

This program makes a table with the share of imports by type of good (both produced and inputs, produced but not an input, an input but not produced, and neither)

The program also has commented out code to make the same table with the levels of imports


*/




*1.  import table
import excel "$input\afft_restat_01.xlsx", ///
	sheet("import_flow_types") firstrow clear

	
	
*2.  reshape to long by transaction type

foreach vv in bothf prodf_nif inputf_np nonef {
    gen `vv'1=al_imp_`vv'+rp_imp_`vv'
	rename al_imp_`vv' `vv'2
	rename rp_imp_`vv' `vv'3
	}



reshape long bothf prodf_nif inputf_np nonef, i(mne_status) j(type) 
	

label define types 1 "Total" 2 "Arm's-Length" 3 "Related-Party"

label values type types

label variable nonef "Not Input or Produced"
label variable bothf "Both Input \& Produced"
label variable inputf_np "Input, Not Produced"
label variable prodf_nif "Not Input, Produced"
	
*3. export levels table 
order mne_status type bothf prodf_nif inputf_np nonef

/*
export excel using "$figs/appendix_tables.xls", ///
	sheet("imports_by_type") sheetreplace first(varlabels)
*/

*4 calculate shares
egen all=rowtotal(bothf prodf_nif inputf_np nonef)


foreach vv in bothf prodf_nif inputf_np nonef {
    gen double sh_`vv'=round(`vv'/all,.01)
	}
	

	
format %9.2f sh*

label variable sh_nonef "Not Input or Produced"
label variable sh_bothf "Both Input \& Produced"
label variable sh_inputf_np "Input, Not Produced"
label variable sh_prodf_nif "Not Input, Produced"



export excel mne_status type sh* using "$figs/appendix_tables.xls", ///
	sheet("TABLE_A8") keepcellfmt first(varlabels) sheetreplace 
